<template>
	<div>
		<!--新增界面-->
		<el-dialog title="新增备案号" v-loading.fullscreen.lock="loading" element-loading-text="处理中......" :visible.sync="dialogVisible" size="full" :close-on-click-modal="false" :close-on-press-escape="false" :before-close="off">
			  <el-form label-width="150px">
			  <el-row :span="24">
			  	<el-col :span="6">
					<el-form-item label="备案号中文名称" required>
						<el-input v-model="formData.efilecname" size="small"></el-input>
					</el-form-item>
					<el-form-item label="备案号英文名称" required>
						<el-input v-model="formData.efileename" size="small"></el-input>
					</el-form-item>
					<el-form-item label="匹配层级" required>
						<el-select v-model="formData.matchlevel" placeholder="请选择" filterable size="small">
							<el-option v-for="item in matchlevelOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="归属险种代码" v-show="showGroups.riskShow">
						<el-input v-model="formData.riskcode" size="small"></el-input>
					</el-form-item>
					<el-form-item label="归属险种名称" v-show="showGroups.riskShow">
						<el-input v-model="formData.riskname" size="small"></el-input>
					</el-form-item>
					<el-form-item label="归属方案代码" v-show="showGroups.planShow">
						<el-input v-model="formData.plancode" size="small"></el-input>
					</el-form-item>
					<el-form-item label="归属方案名称" v-show="showGroups.planShow">
						<el-input v-model="formData.planname" size="small"></el-input>
					</el-form-item>
					<el-form-item label="条款代码" v-show="showGroups.kindShow" required>
						<el-input type="textarea" v-model="formData.kindcode" size="small" readonly @dblclick.native="openKindSelectDialog()"></el-input>
					</el-form-item>
					<el-form-item label="条款名称" v-show="showGroups.kindShow" required>
						<el-input type="textarea" v-model="formData.kindcname" size="small" readonly></el-input>
					</el-form-item>
					<el-form-item label="条款版本" v-show="showGroups.kindShow" required>
						<el-input type="textarea" v-model="formData.kindversion" size="small" readonly></el-input>
					</el-form-item>
					<el-form-item label="备案号有效开始时间" required>
						<el-date-picker type="date" placeholder="选择日期" v-model="formData.startdate" :editable="false" size="small" style="width:100%"></el-date-picker>
					</el-form-item>
					<el-form-item label="备案号有效结束时间" required>
						<el-date-picker type="date" placeholder="选择日期" v-model="formData.enddate" :editable="false" size="small" style="width:100%"></el-date-picker>
					</el-form-item>
					<el-form-item label="渠道">
						<el-select v-model="arrayChannels" placeholder="请选择" multiple filterable size="small">
							<el-option v-for="item in channelOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-form-item>
			  	</el-col>
			  	<el-col :span="6">
			  		<el-form-item label="有效性">
						<el-select v-model="formData.validatestatus" placeholder="请选择" filterable size="small">
							<el-option v-for="item in validOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="报备单位">
						<el-input v-model="formData.submitcom" size="small"></el-input>
					</el-form-item>
					<el-form-item label="产品名称">
						<el-input v-model="formData.productname" size="small"></el-input>
					</el-form-item>
					<el-form-item label="报送类型">
						<el-select v-model="formData.submittype" placeholder="请选择" filterable size="small">
							<el-option v-for="item in submittypeOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="开发方式">
						<el-select v-model="formData.devtype" placeholder="请选择" filterable size="small">
							<el-option v-for="item in devtypeOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="管理类别">
						<el-select v-model="formData.managetype" placeholder="请选择" filterable size="small">
							<el-option v-for="item in managetypeOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="主、附加险类型">
						<el-select v-model="formData.kindtype" placeholder="请选择" filterable size="small">
							<el-option v-for="item in kindtypeOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="产品类别">
						<el-select v-model="formData.producttype" placeholder="请选择" filterable size="small">
							<el-option v-for="item in producttypeOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="开办日期">
						<el-date-picker type="date" placeholder="选择日期" v-model="formData.opendate" :editable="false" size="small" style="width:100%"></el-date-picker>
					</el-form-item>
					<el-form-item label="批复日期">
						<el-date-picker type="date" placeholder="选择日期" v-model="formData.approvaldate" :editable="false" size="small" style="width:100%"></el-date-picker>
					</el-form-item>
					<el-form-item label="经营范围">
						<el-input v-model="formData.busscope" size="small"></el-input>
					</el-form-item>
			  	</el-col>
			  	<el-col :span="6">
			  		<el-form-item label="经营区域">
						<el-input v-model="formData.busarea" size="small"></el-input>
					</el-form-item>
			  		<el-form-item label="报送文件编号">
						<el-input v-model="formData.docnum" size="small"></el-input>
					</el-form-item>
			  		<el-form-item label="年度">
						<el-date-picker v-model="formData.year" align="right" type="year" placeholder="选择年" :editable="false" size="small" style="width:100%"></el-date-picker>
					</el-form-item>
					<el-form-item label="产品性质">
						<el-input v-model="formData.productnature" size="small"></el-input>
					</el-form-item>
					<el-form-item label="费率或基础费率">
						<el-input v-model="formData.rate" size="small"></el-input>
					</el-form-item>
					<el-form-item label="费率浮动区间">
						<el-input v-model="formData.raterange" size="small"></el-input>
					</el-form-item>
					<el-form-item label="费率浮动系数">
						<el-input v-model="formData.ratecoefficient" size="small"></el-input>
					</el-form-item>
					<el-form-item label="是否有电子保单">
					<el-select v-model="formData.hasepolicy" placeholder="请选择" filterable size="small">
							<el-option v-for="item in hasepolicyOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="保险期间">
						<el-input v-model="formData.period" size="small"></el-input>
					</el-form-item>
					<el-form-item label="绝对免赔率（额）">
						<el-input v-model="formData.deductible" size="small"></el-input>
					</el-form-item>
					<el-form-item label="相对免赔率（额）">
						<el-input v-model="formData.reldeductibe" size="small"></el-input>
					</el-form-item>
			  	</el-col>
			  	<el-col :span="6">
			  		<el-form-item label="保险责任">
						<el-input v-model="formData.insliab" size="small"></el-input>
					</el-form-item>
			  		<el-form-item label="产品联系人">
						<el-input v-model="formData.linkname" size="small"></el-input>
					</el-form-item>
					<el-form-item label="产品联系方式">
						<el-input v-model="formData.linknum" size="small"></el-input>
					</el-form-item>
					<el-form-item label="产品个团属性">
						<el-select v-model="formData.productattr" placeholder="请选择" filterable size="small">
							<el-option v-for="item in productattrOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="签发人">
						<el-input v-model="formData.signname" size="small"></el-input>
					</el-form-item>
					<el-form-item label="法律审核人">
						<el-input v-model="formData.legalname" size="small"></el-input>
					</el-form-item>
					<el-form-item label="精算审核人">
						<el-input v-model="formData.actuarialname" size="small"></el-input>
					</el-form-item>
					<el-form-item label="销售推广名称">
						<el-input v-model="formData.salepromname" size="small"></el-input>
					</el-form-item>
					<el-form-item label="销售区域">
						<el-input v-model="formData.salearea" size="small"></el-input>
					</el-form-item>
					<el-form-item label="销售渠道">
						<el-input v-model="formData.salechannel" size="small"></el-input>
					</el-form-item>
					<el-form-item label="其他产品信息">
						<el-input v-model="formData.otherinfo" size="small"></el-input>
					</el-form-item>
			  	</el-col>
			  	<el-col :span="24">
			  		<el-form-item label="审核人备注">
						<el-input type="textarea" v-model="formData.attribute2" size="small"></el-input>
					</el-form-item>
			  	</el-col>
			  </el-row>

			  <el-row type="flex" :span="24" justify="space-around">
				<el-col :span="16">
					<el-table :data="kinds" border style="width: 100%;" :highlight-current-row="true">
						<el-table-column prop="kindcode" label="条款代码" width="120"></el-table-column>
						<el-table-column prop="kindcname" label="条款名称" show-overflow-tooltip min-width="300"></el-table-column>
						<el-table-column prop="picture" label="备案号图片/文件" min-width="240">
						      <template scope="props">
							<input type="file" class="efileImg" :id='props.row.kindcode' @change='addPicture($event,props.row.kindcode)'>
						      </template>
						</el-table-column>
					</el-table>
				</el-col>
			</el-row>

			</el-form>
				<br>
				<div align="center">
					<span slot="footer">
						<el-button @click="off">取 消</el-button>
						<el-button type="success" @click="add">新 增</el-button>
					</span>	
				</div>
		</el-dialog>
		<EFile2KindSelect v-if="showKindSelectDialog"></EFile2KindSelect>
	</div>
</template>

<script>

import EFileAPI from "../../../../js/production/eFile/eFileAPI"
import EFile2KindSelect from "./EFile2KindSelect";
import Constant from "../../../../js/production/constant";

  export default {
  	components : {
  		EFile2KindSelect,
  	},
	data() {
		return {
			dialogVisible: true,
			formData: {
				efilecode : '',
				matchlevel : 'kind',
				efilecname : '',
				efileename : '',
				riskcode : 'F',
				riskversion : 'F',
				plancode : '',
				planname : '',
				riskname : '',
				kindcode : '',
				kindversion : '',
				kindcname : '',
				startdate : '',
				enddate : '',
				path : '',
				imgname : '',
				imglength : '',
				imgwidth : '',
				flag : '',
				validatestatus : '1',
				imgname2 : '',
				imglength2 : '',
				imgwidth2 : '',
				channel : '',
				submitcom : '',
				productname :'',
				submittype : '',
				devtype : '',
				kindtype : '',
				managetype : '',
				producttype : '',
				opendate : '',
				approvaldate : '',
				busscope : '',
				busarea :'',
				docnum : '',
				year : '',
				productnature :'',
				rate : '',
				raterange : '',
				ratecoefficient : '',
				hasepolicy : '',
				period : '',
				deductible : '',
				reldeductibe : '',
				insliab : '',
				attribute1 : '',
				attribute2 : '',
				linkname : '',
				linknum : '',
				productattr : '',
				signname : '',
				legalname : '',
				actuarialname : '',
				salepromname : '',
				salearea : '',
				salechannel : '',
				otherinfo : '',
				attribute3 : '',
				file1 : null,
			},
			arrayChannels : [],
			kinds : [],
			matchlevelOptions : [
				{label : 'kind-条款',value : 'kind'},
				// {label : 'plan-方案',value : 'plan'},
				// {label : 'risk-险种',value : 'risk'},
			],
			validOptions: [
				{label : '1-有效',value: '1'},
				{label : '0-无效',value: '0'}
			],
			hasepolicyOptions: [
				{label : '1-是',value: '1'},
				{label : '0-否',value: '0'}
			],
			channelOptions: [
				{label : '1-传统渠道',value: '1'},
				{label : '2-电销渠道',value: '2'},
				{label : '3-网销渠道',value: '3'},
			],
			submittypeOptions : [
				{label : '1-新产品',value : '1'},
				{label : '2-修订产品',value : '2'},
				{label : '99-其他',value : '99'},
			],
			devtypeOptions : [
				{label : '1-使用示范条款及参考纯风险损失率',value : '1'},
				{label : '2-仅使用示范条款',value : '2'},
				{label : '3-有示范条款未使用',value : '3'},
				{label : '4-自主开发',value : '4'},
				{label : '99-其他',value : '99'},
			],
			kindtypeOptions : [
				{label : '1-附加险',value : '1'},
				{label : '2-主险',value : '2'},
				{label : '3-特约',value : '3'},
			],
			managetypeOptions : [
				{label : '1-审批',value : '1'},
				{label : '2-备案',value : '2'},
				{label : '3-报告',value : '3'},
				{label : '4-全部',value : '4'},
			],
			producttypeOptions : [
				{label : '1-机动车辆保险',value : '1'},
				{label : '2-企业财产保险',value : '2'},
				{label : '3-家庭财产保险',value : '3'},
				{label : '4-工程保险',value : '4'},
				{label : '5-责任保险',value : '5'},
				{label : '6-信用保险',value : '6'},
				{label : '7-保证保险',value : '7'},
				{label : '8-船舶保险',value : '8'},
				{label : '9-货物运输保险',value : '9'},
				{label : '10-特殊风险保险',value : '10'},
				{label : '11-农业保险',value : '11'},
				{label : '12-健康保险',value : '12'},
				{label : '13-意外伤害保险',value : '13'},
				{label : '14-其他',value : '14'},
				{label : '15-全部',value : '15'},
			],
			productattrOptions : [
				{label : '1-个人',value : '1'},
				{label : '2-团体',value : '2'},
				{label : '3-个团均可',value : '3'},
				{label : '99-其他',value : '99'},
			],
			showGroups : {
				riskShow : false,
				planShow : false,
				kindShow : true
			},
			uploadUrl : Constant.urls.insertEFile,
			showKindSelectDialog : false,
			loading : false,
		}
	},
	watch : {
		arrayChannels(newVal,oldVal) {
			let channels = [];
			channels = newVal;
			this.formData.channel = '';
			for(let i = 0; i < channels.length - 1; i++) {
				this.formData.channel += channels[i] + ",";
			}
			if(this.arrayChannels.length > 0) {
				this.formData.channel += channels[channels.length - 1];
			}

		},
		kinds(newVal,oldVal) {
			$(".efileImg").val("");
		}
	},
	mounted() {
		if('undefined' != typeof(this.$parent.showEFileAddDialog)) {
			this.kinds = this.$parent.selectedRows;
			let code = '';
			let name = '';
			let version = '';
			for(let i = 0; i < this.kinds.length; i++) {
				code += this.kinds[i].kindcode + ',';
				name += this.kinds[i].kindcname + ',';
				version += this.kinds[i].kindversion + ',';
			}
			this.formData.kindcode = code.substring(0,code.length - 1);
			this.formData.kindcname = name.substring(0,name.length - 1);
			this.formData.kindversion = version.substring(0,version.length - 1);
		}
	},
	methods: {
		add() {
			if('undefined' != typeof(this.formData.startdate) && 'undefined' != typeof(this.formData.enddate) && this.formData.startdate != '' && this.formData.enddate != '') {
				let tempStartDate = this.formData.startdate;
				let tempEndDate = this.formData.enddate;
				if('string' == typeof(tempStartDate)) {
					tempStartDate = new Date(tempStartDate);
				}
				if('string' == typeof(tempEndDate)) {
					tempEndDate = new Date(tempEndDate);
				}
				if(tempEndDate < tempStartDate) {
					this.$message({type: 'error',message: '【备案号有效开始日期】不能小于【备案号有效结束日期】'});
					this.formData.enddate = null;
					return;
				}
			}
			if('undefined' != typeof(this.formData.opendate) && 'undefined' != typeof(this.formData.approvaldate) && this.formData.opendate != '' && this.formData.approvaldate != '') {
				let tempOpenDate = this.formData.opendate;
				let tempApprovalDate = this.formData.approvaldate;
				if('string' == typeof(tempOpenDate)) {
					tempOpenDate = new Date(tempOpenDate);
				}
				if('string' == typeof(tempApprovalDate)) {
					tempApprovalDate = new Date(tempApprovalDate);
				}
				if(tempApprovalDate < tempOpenDate) {
					this.$message({type: 'error',message: '【批复日期】不能小于【开办日期】'});
					this.formData.approvaldate = null;
					return;
				}
			}
			this.formData.startdate = this.formData.startdate.toString();
			this.formData.enddate = this.formData.enddate.toString();
			this.formData.opendate = this.formData.opendate.toString();
			this.formData.approvaldate = this.formData.approvaldate.toString();
			this.formData.year = this.formData.year.toString();
			EFileAPI.add(this);
		},
		off() {
			if('undefined' != typeof(this.$parent.showEFileAddDialog)) {
				this.$parent.showEFileAddDialog = false;
			} else {
				this.$parent.showAddDialog = false;
			}
			
		},
		show() {
			switch(this.formData.matchlevel) {
				case 'kind' :
					this.showGroups.kindShow = true;
					this.showGroups.riskShow = false;
					this.showGroups.planShow = false;
					break;
				case 'risk' :
					this.showGroups.kindShow = false;
					this.showGroups.riskShow = true;
					this.showGroups.planShow = false;
					break;
				case 'plan' :
					this.showGroups.kindShow = false;
					this.showGroups.riskShow = true;
					this.showGroups.planShow = true;
					break;
			}
		},
		openKindSelectDialog() {
			EFileAPI.openKindSelectDialog(this);
		},
		addPicture(event,kindcode) {
			if(kindcode.substring(2,3) == 'M') {
				if(event.target.files[0].type !== 'application/pdf') {
					this.$message({type: 'error',message: '条款【' + kindcode + '】只能上传PDF文件!'});
					$('#' + kindcode).val('');
					return;
				}
			} else if (kindcode.substring(2,3) == 'S') {
				if(event.target.files[0].type !== 'image/bmp') {
					this.$message({type: 'error',message: '条款【' + kindcode + '】只能上传bmp图片!'});
					$('#' + kindcode).val('');
					return;
				}
			}
			this.formData['img' + kindcode] = event.target.files[0];
		},
	}
  }
</script>
